function getStudentOverview() {
    axios.get('/student/overview').then(e => {
        // console.log(e);
        if (e.data.code === 0) {
            // const {avgAge,avgSalary,proportion,total}=e.data.data;
            // document.querySelector('.avgAge').innerText=avgAge;
            // document.querySelector('.avgSalary').innerText=avgSalary;
            // document.querySelector('.proportion').innerText=proportion;
            // document.querySelector('.total').innerText=total;
            const obj = e.data.data
            for (const key in obj) {
                document.querySelector(`.${key}`).innerText = obj[key];
            }
        }
    })
}

getStudentOverview()


//获取全部学员信息封装

getStudentList()

function getStudentList() {
    axios.get('/student/list').then(e => {
        const list = e.data.data
        salaryLine(list)
        HomeTown(list)
    })
}



//薪资折线图
function salaryLine(list) {
    // console.log(list);
    //期望薪资
    const salarys = list.map(v =>
        v.salary
    );
    // console.log(salarys);
    //实际工资
    const truesalarys = list.map(v =>
        v.truesalary
    );
    // console.log(truesalarys);
    //拆分名单
    const names = list.map(v =>
        v.name
    );

    // 1 获取有宽度和高度的div 元素 传入 echarts 实例化
    const myChart = echarts.init(document.querySelector('.line'));

    // 指定图表的配置项和数据
    const option = {
        // 设置线条颜色
        color: ['orange', 'green'],
        title: {
            text: '薪资 Salary',
        },
        tooltip: {
            trigger: 'axis',
        },
        legend: {},
        // 工具箱
        toolbox: {
            show: false,
            feature: {
                dataZoom: {
                    yAxisIndex: 'none',
                },
                dataView: {
                    readOnly: false
                },
                magicType: {
                    type: ['line', 'bar']
                },
                restore: {},
                saveAsImage: {},
            },
        },
        xAxis: {
            type: 'category',
            boundaryGap: false,
            data: names,
        },
        yAxis: {
            type: 'value',

        },
        // 滑块
        dataZoom: [{
                type: 'inside',
                start: 0,
                end: 10,
            },
            {
                start: 0,
                end: 10, // 总宽度100  10 十分之一 ，  这个设置要上 上面的设置 保持一致
            },
        ],
        series: [{
                name: '期望薪资',
                type: 'line',
                smooth: true, // 线条平滑
                symbol: 'circle', // 实心
                data: salarys,

            },
            {
                name: '实际薪资',
                type: 'line',
                symbol: 'circle', // 实心

                smooth: true, // 线条平滑
                data: truesalarys,

            },
        ],
    };

    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);


}


//籍贯饼图
function HomeTown(list) {
    // console.log(list);
    const newList = []
    list.forEach(v => {
        const index = newList.findIndex(vv => vv.name === v.province);
        if (index === -1) {
            newList.push({
                value: 1,
                name: v.province
            })
        } else {
            newList[index].value++
        }
    });

    // 基于准备好的dom，初始化echarts实例
    const myChart = echarts.init(document.querySelector('.pie'));

    // 指定图表的配置项和数据
    const option = {
        title: {
            text: '籍贯 HomeTown',
        },
        series: [{
            name: 'Nightingale Chart',
            type: 'pie',
            radius: [20, 180],
            center: ['50%', '50%'],
            roseType: 'area',
            itemStyle: {
                borderRadius: 8
            },
            data: newList
        }]
    };
    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);


}



const toggleBatchBtn = document.querySelector('#toggleBatchBtn');
const batchUl = document.querySelector('#batch ');


toggleBatchBtn.addEventListener('click', e => {
    batchUl.classList.toggle('show');

})

batchUl.addEventListener('click', e => {
    if (e.target.nodeName === 'A') {
        const v = e.target.dataset.index;
        getScorebatch(v)
    
    }
})


//成绩柱状图
function getScorebatch(v) {
    axios.get(`/score/batch?batch=${v}`).then(e => {
        if (e.data.code === 0) {
            const {
                avgScore,
                group,
                gt60,
                gt80,
                lt60
            } = e.data.data;

            // 基于准备好的dom，初始化echarts实例
            const myChart = echarts.init(document.querySelector('.barChart'));

            const option = {
                
                grid:{
                    top:30,
                    bottom:20,
                    
                },
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'cross',
                        crossStyle: {
                            color: '#999'
                        }
                    }
                },

                legend: {
                    data: [
                        '平均分',
                        '低于60分人数',
                        '60分-80分之间人数',
                        '高于80分的人数',
                    ],
                },
                xAxis: [{
                    type: 'category',
                    data: group,
                    axisPointer: {
                        type: 'shadow'
                    }
                }],
                yAxis: [{
                        type: 'value',
                        min: 0,
                        max: 100,
                        interval: 10,
                        axisLabel: {
                            formatter: '{value}分'
                        }
                    },
                    {
                        type: 'value',
                        min: 0,
                        max: 10,
                        interval: 1,
                        axisLabel: {
                            formatter: '{value} 人'
                        }
                    }
                ],
                series: [{
                        name: '平均分',
                        type: 'bar',
                        barWidth:20,
                        tooltip: {
                            valueFormatter: function (value) {
                                return value + '分';
                            }
                        },
                        data:avgScore
                    },
                    {
                        name: '低于60分人数',
                        yAxisIndex: 1, // 参考右侧的y轴
                        barWidth:20,
                        type: 'bar',
                        tooltip: {
                            valueFormatter: function (value) {
                                return value + '分';
                            }
                        },
                        data:lt60
                    },
                    {
                        name: '60分-80分之间人数',
                        yAxisIndex: 1, // 参考右侧的y轴
                        barWidth:20,
                        type: 'bar',
                        tooltip: {
                            valueFormatter: function (value) {
                                return value + '分';
                            }
                        },
                        data:gt60
                    },
                    {
                        name: '高于80分的人数',
                        yAxisIndex: 1, // 参考右侧的y轴
                        barWidth:20,
                        type: 'bar',
                        tooltip: {
                            valueFormatter: function (value) {
                                return value + '分';
                            }
                        },
                        data:gt80
                    },

                ]
            };
            // 使用刚指定的配置项和数据显示图表。
            myChart.setOption(option);
        }
    })
}
// console.log(1);
getScorebatch(1)



//地图
        // 基于准备好的dom，初始化echarts实例
        const myChart = echarts.init(document.querySelector('.map'));

        const points = [{
            value: [118.8062, 31.9208],
            itemStyle: {
                color: '#4ab2e5'
            }
        }, {
            value: [127.9688, 45.368],
            itemStyle: {
                color: '#4fb6d2'
            }
        }, {
            value: [110.3467, 41.4899],
            itemStyle: {
                color: '#52b9c7'
            }
        }, {
            value: [125.8154, 44.2584],
            itemStyle: {
                color: 'red'
            }
        }, {
            value: [116.4551, 40.2539],
            itemStyle: {
                color: '#f34e2b'
            }
        }, {
            value: [123.1238, 42.1216],
            itemStyle: {
                color: '#f56321'
            }
        }, {
            value: [114.4995, 38.1006],
            itemStyle: {
                color: '#f56f1c'
            }
        }, {
            value: [117.4219, 39.4189],
            itemStyle: {
                color: 'pink'
            }
        }, {
            value: [112.3352, 37.9413],
            itemStyle: {
                color: '#f58f0e'
            }
        }, {
            value: [109.1162, 34.2004],
            itemStyle: {
                color: '#f5a305'
            }
        }, {
            value: [103.5901, 36.3043],
            itemStyle: {
                color: '#e7ab0b'
            }
        }, {
            value: [106.3586, 38.1775],
            itemStyle: {
                color: 'orange'
            }
        }, {
            value: [101.4038, 36.8207],
            itemStyle: {
                color: '#d5b314'
            }
        }, {
            value: [103.9526, 30.7617],
            itemStyle: {
                color: '#c1bb1f'
            }
        }, {
            value: [108.384366, 30.439702],
            itemStyle: {
                color: 'purple'
            }
        }, {
            value: [113.0823, 28.2568],
            itemStyle: {
                color: '#a6c62c'
            }
        }, {
            value: [102.9199, 25.46639],
            itemStyle: {
                color: '#96cc34'
            }
        }, {
            value: [119.4543, 25.9222]
        }]

        echarts.registerMap('china', mapData); // geoJson 请求回来的数据 变量

        const option = {
            backgroundColor: '#fff',
            geo: {
                map: 'china',
                aspectScale: 0.75, //长宽比
                zoom: 1.1,
                roam: false,
                itemStyle: {
                    normal: {
                        areaColor: {
                            type: 'radial',
                            x: 0.5,
                            y: 0.5,
                            r: 0.8,
                            colorStops: [{
                                offset: 0,
                                color: '#09132c' // 0% 处的颜色
                            }, {
                                offset: 1,
                                color: '#274d68' // 100% 处的颜色
                            }],
                            globalCoord: true // 缺省为 false
                        },
                        shadowColor: 'rgb(58,115,192)',
                        shadowOffsetX: 10,
                        shadowOffsetY: 11
                    },
                    emphasis: {
                        areaColor: '#2AB8FF',
                        borderWidth: 0,
                        color: 'green',
                        label: {
                            show: false
                        }
                    }
                },
                regions: [{
                    name: '南海诸岛',
                    itemStyle: {
                        areaColor: 'rgba(0, 10, 52, 1)',

                        borderColor: 'rgba(0, 10, 52, 1)',
                        normal: {
                            opacity: 0,
                            label: {
                                show: false,
                                color: "#009cc9",
                            }
                        }
                    },


                }],
            },
            series: [{
                    type: 'map',
                    roam: false,
                    label: {
                        normal: {
                            show: true,
                            textStyle: {
                                color: '#1DE9B6'
                            }
                        },
                        emphasis: {
                            textStyle: {
                                color: 'rgb(183,185,14)'
                            }
                        }
                    },

                    itemStyle: {
                        normal: {
                            borderColor: 'pink',
                            borderWidth: 1,
                            areaColor: {
                                type: 'radial',
                                x: 0.5,
                                y: 0.5,
                                r: 0.8,
                                colorStops: [{
                                    offset: 0,
                                    color: '#09132c' // 0% 处的颜色
                                }, {
                                    offset: 1,
                                    color: '#274d68' // 100% 处的颜色
                                }],
                                globalCoord: true // 缺省为 false
                            },
                        },
                        emphasis: {
                            areaColor: 'pink',
                            //    shadowColor: 'rgb(12,25,50)',
                            borderWidth: 0.1
                        }
                    },
                    zoom: 1.1,
                    //     roam: false,
                    map: 'china' //使用
                    // data: this.difficultData //热力图数据   不同区域 不同的底色
                }, {
                    type: 'effectScatter',
                    coordinateSystem: 'geo',
                    showEffectOn: 'render',
                    zlevel: 1,
                    rippleEffect: {
                        period: 15,
                        scale: 4,
                        brushType: 'fill'
                    },
                    hoverAnimation: true,
                    label: {
                        normal: {
                            formatter: '{b}',
                            position: 'right',
                            offset: [15, 0],
                            color: 'pink',
                            show: true
                        },
                    },
                    itemStyle: {
                        normal: {
                            color: '#1DE9B6',
                            shadowBlur: 10,
                            shadowColor: '#333'
                        }
                    },
                    symbolSize: 12,
                    data: points
                }, //地图线的动画效果
                {
                    type: 'lines',
                    zlevel: 2,
                    effect: {
                        show: true,
                        period: 4, //箭头指向速度，值越小速度越快
                        trailLength: 0.4, //特效尾迹长度[0,1]值越大，尾迹越长重
                        symbol: 'arrow', //箭头图标
                        symbolSize: 7, //图标大小
                    },
                    lineStyle: {
                        normal: {
                            color: '#1DE9B6',
                            width: 1, //线条宽度
                            opacity: 0.1, //尾迹线条透明度
                            curveness: .3 //尾迹线条曲直度
                        }
                    },
                    data: [{
                        coords: [
                            [118.8062, 31.9208],
                            [112.57, 22.26],
                        ],
                        lineStyle: {
                            color: 'pink'
                        }
                    }, 
                    {
                        coords: [
                            [119.4543, 25.9222],
                            [112.57, 22.26],
                        ],
                        lineStyle: {
                            color: '#4fb6d2'
                        }
                    }, 
                    {
                        coords: [
                            [110.3467, 41.4899],
                            [112.57, 22.26],
                        ],
                        lineStyle: {
                            color: 'red'
                        }
                    }, {
                        coords: [
                            [125.8154, 44.2584],
                            [112.57, 22.26],
                        ],
                        lineStyle: {
                            color: '#5abead'
                        }
                    }, {
                        coords: [
                            [116.4551, 40.2539],
                            [112.57, 22.26],
                        ],
                        lineStyle: {
                            color: 'orange'
                        }
                    }, {
                        coords: [
                            [123.1238, 42.1216],
                            [112.57, 22.26],
                        ],
                        lineStyle: {
                            color: '#f56321'
                        }
                    }, {
                        coords: [
                            [114.4995, 38.1006],
                            [112.57, 22.26],
                        ],
                        lineStyle: {
                            color: 'purple'
                        }
                    }, {
                        coords: [
                            [117.4219, 39.4189],
                            [112.57, 22.26],
                        ],
                        lineStyle: {
                            color: '#f58414'
                        }
                    }, {
                        coords: [
                            [112.3352, 37.9413],
                            [112.57, 22.26],
                        ],
                        lineStyle: {
                            color: '#f58f0e'
                        }
                    }, {
                        coords: [
                            [109.1162, 34.2004],
                            [112.57, 22.26],
                        ],
                        lineStyle: {
                            color: '#f5a305'
                        }
                    }, {
                        coords: [
                            [103.5901, 36.3043],
                            [112.57, 22.26],
                        ],
                        lineStyle: {
                            color: 'yellowgreen'
                        }
                    }, {
                        coords: [
                            [106.3586, 38.1775],
                            [112.57, 22.26],
                        ],
                        lineStyle: {
                            color: '#dfae10'
                        }
                    }, {
                        coords: [
                            [101.4038, 36.8207],
                            [112.57, 22.26],
                        ],
                        lineStyle: {
                            color: 'aqua'
                        }
                    }, {
                        coords: [
                            [103.9526, 30.7617],
                            [112.57, 22.26],
                        ],
                        lineStyle: {
                            color: '#c1bb1f'
                        }
                    }, {
                        coords: [
                            [108.384366, 30.439702],
                            [112.57, 22.26],
                        ],
                        lineStyle: {
                            color: '#b9be23'
                        }
                    }, {
                        coords: [
                            [113.0823, 28.2568],
                            [112.57, 22.26],
                        ],
                        lineStyle: {
                            color: 'red'
                        }
                    }, {
                        coords: [
                            [102.9199, 25.46639],
                            [112.57, 22.26],
                        ],
                        lineStyle: {
                            color: '#96cc34'
                        }
                    }]
                }
            ]
        };

        myChart.setOption(option, true);